Multithreaded computer programs and/or multiprocessor computer systems have multiple threads and/or processors that share use of a number of resources. Access coordination and/or synchronization serve to organize access by a plurality of the processors to one or more of the shared resources. A tool for access coordination and/or synchronization comprises a lock, for example, a spinlock.
A computer architecture employs a ticket-serving algorithm to implement spinlocks. Each lock comprises both a ticket variable and a serving value variable, which indicates the ticket value currently being served. For example, these variables initially comprise a same value, indicating that the particular lock is available.
Each processor that desires the lock takes the next available ticket. When a processor takes a ticket, the processor increments the value of the next available ticket. If the ticket value taken matches the serving value, then the processor owns the spinlock. If the ticket value is greater than the serving value, then the processor waits for a turn on the spinlock.